package com.xiaoxie.mapper;


import com.xiaoxie.DTO.UserDTO;
import com.xiaoxie.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 小谢
 * @since 2023-10-13
 */
@Mapper
public interface UserDao {
    /**
     * 初始化用户学习状态
     */
    @Update("UPDATE user SET LearnFinish = 'false', wordInit='false' ,lastTime=NOW() WHERE lastTime < DATE(NOW()) and userAccount=#{account}")
    void init(String account);

    /**
     * 查询用户
     *
     * @param account
     * @return
     */
    @Select("select * from user where userAccount=#{account}")
    User select(String account);

    /**
     * 更行用户状态
     *
     * @param account
     */
    @Update("update user set LearnFinish='true' ,lastTime=now() where userAccount=#{account}")
    void updateFinish(String account);

    /**
     * 更新用户单词学习状态
     * @param account
     */
    @Update("update user set LearnFinish='false' ,lastTime=now() where userAccount=#{account}")
    void updateFalseFinish(String account);

    /**
     * 设置用户单词初始化状态
     * @param account
     */
    @Update("update user set wordInit='true' where userAccount=#{account}")
    void updateWordInit(String account);

    /**
     * 用户登录
     * @param userDTO
     * @return
     */
    @Select("select * from user where userAccount=#{userAccount} and userpwd=#{userpwd}")
    User login(UserDTO userDTO);

    @Insert("insert into user values(#{id},#{userDTO},#{userDTO},#{pwd},'男','','普通用户','false',now(),'false')")
    void enroll(Integer id,String userDTO,String pwd);
}
